Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Set childReportID of the optimistic IOU report action #37232

Merged
merged 11 commits into from
Mar 11, 2024

Conversation

paultsimura
Copy link
Contributor

@paultsimura paultsimura commented Feb 26, 2024

Details

When creating a money request, set the report action's childReportID to the optimistically created money request reportID.

Fixed Issues

$ #33114
PROPOSAL: #33114 (comment)

Tests

Same as QA

Offline tests

Same as QA

QA Steps

Test 1:

  1. Go offline
  2. Request money: repeat for each of the manual, scan, and distance requests;
  3. Navigate to the newly created money request report
  4. Verify it's showing the correct data
  5. Go online
  6. Verify the report doesn't disappear after the data is fetched from BE

Test 2:

  1. Go offline
  2. Click "FAB" -> Request money -> Scan
  3. Select a receipt, click "next"
  4. Next to a user, click "Split"
  5. Proceed to create a 1:1 split
  6. Click on the created Split preview
  7. Enter the amount manually and click "Split"
  8. Navigate to the newly created 1:1 money request report
  9. Verify it's showing the correct data
  10. Go online
  11. Verify the report changes to Not Found (this is expected for now because the corresponding BE changes are pending).
  12. Navigate back (to the IOU report)
  13. Click the IOU Preview again
  14. Verify the 1:1 money request report opens and shows the correct data.

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
android-compressed.mp4
Android: mWeb Chrome
chrome-compressed.mp4
iOS: Native
Simulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-02-27.at.00.09.34-compressed.mp4
iOS: mWeb Safari
Simulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-02-27.at.00.16.14-compressed.mp4
MacOS: Chrome / Safari
Screen.Recording.2024-02-26.at.23.41.37-compressed.mp4
MacOS: Desktop
Screen.Recording.2024-02-26.at.23.51.31-compressed.mp4

@paultsimura paultsimura marked this pull request as ready for review February 26, 2024 23:19
@paultsimura paultsimura requested a review from a team as a code owner February 26, 2024 23:19
@melvin-bot melvin-bot bot removed the request for review from a team February 26, 2024 23:19
Copy link

melvin-bot bot commented Feb 26, 2024

@situchan Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@paultsimura
Copy link
Contributor Author

I think we can release without it, but there's a BE fix pending: #33114 (comment)

@situchan
Copy link
Contributor

situchan commented Feb 29, 2024

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
expense-distance.mov
expense-distance-fab.mov
expense-manual.mov
expense-manual-fab.mov
expense-manual-scan.mov
expense-manual-scan-fab.mov
expense-scan.mov
expense-scan-fab.mov
iou-manual.mov
iou-manual-fab.mov
iou-manual-scan.mov
iou-scan.mov
iou-scan-fab.mov
send-fab.mov
split-user-manual.mov
split-user-manual-fab.mov
split-workspace-distance.mov
split-workspace-manual.mov
split-workspace-manual-fab.mov
MacOS: Desktop

@situchan
Copy link
Contributor

situchan commented Mar 3, 2024

Maybe out of scope but there are various glitches as seen in this video:

Screen.Recording.2024-03-03.at.11.58.30.PM.mov
  1. Empty view
Screenshot 2024-03-04 at 12 01 44 AM
  1. Only background
Screenshot 2024-03-04 at 12 01 54 AM
  1. No header
Screenshot 2024-03-04 at 12 02 04 AM
  1. Some info missing in header
Screenshot 2024-03-04 at 12 02 09 AM
  1. After online:
Screenshot 2024-03-04 at 12 02 41 AM

Here's full repro video: (manual request to new (non-Expensify) user in offline mode)

iou-manual.mov

@situchan
Copy link
Contributor

situchan commented Mar 3, 2024

BUG: unavailable workspace on transaction detail header when create expense manual request offline. Same happens on split manual request with workspace

Screenshot 2024-03-04 at 12 39 18 AM
expense-manual-fab.mov

Split:

split-workspace-fab.mov

@situchan
Copy link
Contributor

situchan commented Mar 3, 2024

@paultsimura this is blocker.

Bug not fixed: split manual request with a single user (non-Expensify) from FAB

split-user-manual-fab.mov

@paultsimura
Copy link
Contributor Author

@paultsimura this is blocker.
Bug not fixed: split manual request with a single user from FAB

This one is BE as well, similar to the SendMoney.

@cead22 when creating a Split request and calling the SplitBillAndOpenReport API endpoint, we send the stringified splits among parameters. Each split will now contain the transactionThreadReportID and createdReportActionIDForThread that need to be handled on the BE – currently, the optimistic transaction thread is replaced with another from the BE response.

Here's the params example:

{
    "reportID": "1932415687405820",
    "amount": 2200,
    "splits": "[{\"email\":\"paultsimura@gmail.com\",\"accountID\":15528187,\"amount\":1100},{\"email\":\"paultsimura+qa@gmail.com\",\"accountID\":15528255,\"amount\":1100,\"iouReportID\":\"2941200419003018\",\"chatReportID\":\"1932415687405820\",\"transactionID\":\"7451263110636286127\",\"reportActionID\":\"4265162090444479673\",\"createdChatReportActionID\":\"3058872218140896575\",\"createdIOUReportActionID\":\"792942737366932173\",\"reportPreviewReportActionID\":\"7347533532549283559\",\"transactionThreadReportID\":\"5196953162708250\",\"createdReportActionIDForThread\":\"8302969548555128822\"}]",
    "currency": "PLN",
    "merchant": "(none)",
    "created": "2024-03-03 19:54:14.852",
    "comment": "",
    "category": "",
    "tag": "",
    "billable": false,
    "transactionID": "5684861019807192728",
    "reportActionID": "4158501737745037324",
    "policyID": "_FAKE_"
}

@situchan
Copy link
Contributor

situchan commented Mar 3, 2024

While it's BE issue, I found interesting thing (possible fix in FE).
I tried to create optimistic chat with same user in 2 devices. On 2nd device, after making online, optimistic reportID (wrong one) is automatically replaced with correct reportID.
Can't this be applied to optimistic transaction report as well?

double.optimistic.chat.behavior.mov

@paultsimura
Copy link
Contributor Author

This looks like a workaround.
The original PR about passing the optimistic thread IDs to BE was intended to fix this very issue, it was just not fully implemented.

@paultsimura
Copy link
Contributor Author

BUG: unavailable workspace on transaction detail header when create expense manual request offline. Same happens on split manual request with workspace

Found a fix, working on it...

@paultsimura
Copy link
Contributor Author

paultsimura commented Mar 3, 2024

@situchan I think after this PR this code won't be needed anymore 🤔
It was used to create a thread if a moneyRequestPreview didn't have a child report. But now we are creating and setting it optimistically ever time,

// If the childReportID is not present, we need to create a new thread
const childReportID = action?.childReportID;
if (!childReportID) {
const thread = ReportUtils.buildTransactionThread(action, requestReportID);
const userLogins = PersonalDetailsUtils.getLoginsByAccountIDs(thread.participantAccountIDs ?? []);
Report.openReport(thread.reportID, userLogins, thread, action.reportActionID);
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(thread.reportID));
return;
}

if (!childReportID) {
const thread = ReportUtils.buildTransactionThread(reportAction, reportID);
const userLogins = PersonalDetailsUtils.getLoginsByAccountIDs(thread.participantAccountIDs ?? []);
Report.openReport(thread.reportID, userLogins, thread, reportAction?.reportActionID);
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(thread.reportID));
return;
}

@situchan
Copy link
Contributor

situchan commented Mar 3, 2024

@situchan I think after this PR this code won't be needed anymore 🤔 It was used to create a thread if a moneyRequestPreview didn't have a child report. But now we are creating and setting it optimistically ever time,

// If the childReportID is not present, we need to create a new thread
const childReportID = action?.childReportID;
if (!childReportID) {
const thread = ReportUtils.buildTransactionThread(action, requestReportID);
const userLogins = PersonalDetailsUtils.getLoginsByAccountIDs(thread.participantAccountIDs ?? []);
Report.openReport(thread.reportID, userLogins, thread, action.reportActionID);
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(thread.reportID));
return;
}

if (!childReportID) {
const thread = ReportUtils.buildTransactionThread(reportAction, reportID);
const userLogins = PersonalDetailsUtils.getLoginsByAccountIDs(thread.participantAccountIDs ?? []);
Report.openReport(thread.reportID, userLogins, thread, reportAction?.reportActionID);
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(thread.reportID));
return;
}

They were added in #18760, #25429.
Agree cleanup after we make sure that childReportID in money request action is already coming from backend for any type of money requests.

  1. Login same account on device A & B
  2. Create money request in A
  3. Navigate to transaction detail page in B

@paultsimura
Copy link
Contributor Author

  • Login same account on device A & B
  • Create money request in A
  • Navigate to transaction detail page in B

Do you observe any bug with this? If so – could you please share the recording? I didn't notice anything suspicious

@situchan
Copy link
Contributor

situchan commented Mar 3, 2024

  • Login same account on device A & B
  • Create money request in A
  • Navigate to transaction detail page in B

Do you observe any bug with this? If so – could you please share the recording? I didn't notice anything suspicious

I just shared test case. If you confirm that no bug found on all types of requests, you can remove them as unnecessary codes. We don't wanna be affected by any possible regressions from code cleanup.

@situchan
Copy link
Contributor

situchan commented Mar 3, 2024

Now we should hold PR for BE fix of split, send cases, right?

@paultsimura
Copy link
Contributor Author

Now we should hold PR for BE fix of split, send cases, right?

I'll let @cead22 decide here. This PR won't break the flow because the behavior we have with splits & send flow is already happening in Prod. But just to be sure the BE fix works well with this PR, we can hold.

@paultsimura
Copy link
Contributor Author

If you confirm that no bug found on all types of requests, you can remove them as unnecessary codes. We don't wanna be affected by any possible regressions from code cleanup.

Tests well, both IOU & expense requests:

Screen.Recording.2024-03-03.at.22.02.56-compressed.mp4
Screen.Recording.2024-03-03.at.22.03.51-compressed.mp4

@paultsimura
Copy link
Contributor Author

BUG: unavailable workspace on transaction detail header when create expense manual request offline. Same happens on split manual request with workspace

Fixed ✔️

@cead22
Copy link
Contributor

cead22 commented Mar 4, 2024

@cead22 when creating a Split request and calling the SplitBillAndOpenReport API endpoint, we send the stringified splits among parameters. Each split will now contain the transactionThreadReportID and createdReportActionIDForThread that need to be handled on the BE – currently, the optimistic transaction thread is replaced with another from the BE response.

Thanks for letting me know, I'll make an issue for us to update the back end!

@cead22
Copy link
Contributor

cead22 commented Mar 4, 2024

currently, the optimistic transaction thread is replaced with another from the BE response.

I made the issue, and we can wait for that fix to test this PR, but are you sure the backend replacing the value with a different one, and the issue isn't that we're not setting iouAction.childReportID in the client?

If the backend isn't returning a bad value, then things should work with the front end fix, because we'll navigate to the right report based on that front end value, right?

@situchan
Copy link
Contributor

situchan commented Mar 7, 2024

Works now after removing node modules again and clearing caches

@situchan
Copy link
Contributor

situchan commented Mar 7, 2024

Split scan seems not working. To reproduce, click report preview quickly after scan success

split-user-scan-fab.mov

@situchan
Copy link
Contributor

situchan commented Mar 7, 2024

Test Result: (🟢: pass, 🔴: failed, 🟡: pending test)

Request Manual Manual (receipt) Scan Distance
IOU (from FAB) 🟢 🟢 🟢 New
Expense (from FAB) 🟢 🟢 🟢 🟢
Split with user (from FAB) 🟢 N/A 🔴 New
Split with workspace (from FAB) 🟢 N/A 🔴 N/A
Send (from FAB) 🟢 N/A N/A N/A
IOU (from chat) 🟢 🟢 🟢 New
Expense (from chat) 🟢 🟢 🟢 🟢
Split with users (from group chat) 🟢 N/A 🔴 New
Split with workspace (from chat) 🟢 N/A 🔴 🟢
Send (from chat) 🟢 N/A N/A N/A

(I keep updating fields upon testing)

@situchan
Copy link
Contributor

situchan commented Mar 7, 2024

@paultsimura Let's split testing. Can you please test all above cases (from FAB) for existing report (if you haven't tested)?
I will test non-existing report cases.

@paultsimura
Copy link
Contributor Author

@situchan I've confirmed that all manual requests work fine.
Managed reproduce the issue with scan splits, investigating now...

@paultsimura
Copy link
Contributor Author

@cead22 there is a BE issue with the CompleteSplitBill API call: it doesn't set (and return) the childReportID of the IOU action that we're passing in params. Right after, in an OpenReport call to the BE, the childReportID comes with a different value. And the optimistically created report gets removed:

Screen.Recording.2024-03-07.at.17.02.31-compressed.mp4

Could we get this fixed on the BE side? Seems like so far it's the only API endpoint that's blocking us (if we want to hold for the BE change).

@situchan
Copy link
Contributor

situchan commented Mar 7, 2024

Being many issues are held for this PR and already dragged a lot for past blockers, I suggest to merge without waiting BE fix.

@situchan
Copy link
Contributor

situchan commented Mar 7, 2024

Maybe out of scope but map preview not showing in split distance request:

Screenshot 2024-03-07 at 10 31 04 PM

@situchan
Copy link
Contributor

situchan commented Mar 7, 2024

Tests completed

Result: #37232 (comment)

Copy link
Contributor

@situchan situchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests pass except split scan.

@cead22 all yours

@@ -91,15 +89,7 @@ function MoneyRequestAction({
return;
}

// If the childReportID is not present, we need to create a new thread
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we removing this because we're always creating transaction threads in the backend, and action?.childReportID will be set to the ID of that transaction thread?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We've discussed it briefly here: #37232 (comment)

@@ -926,7 +926,8 @@ function getMoneyRequestInformation(
false,
currentTime,
);
const optimisticTransactionThread = ReportUtils.buildTransactionThread(iouAction, iouReport.reportID);
const optimisticTransactionThread = ReportUtils.buildTransactionThread(iouAction, iouReport);
iouAction.childReportID = optimisticTransactionThread.reportID;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a comment above this line saying why we need to do this? It's not super obvious right away, and it made me wonder if we should be setting this in const iouAction = ReportUtils.buildOptimisticIOUReportAction, but then realized ReportUtils.buildTransactionThread takes iouAction which is created by ReportUtils.buildOptimisticIOUReportAction.

I don't have a good solution for that right now -- it seems like we could generate an optimistic reportID before the calls to ReportUtils.buildOptimisticIOUReportAction and ReportUtils.buildTransactionThread, and pass it to both so we don't have to manually set iouAction.childReportID = optimisticTransactionThread.reportID;, but I'm not sure if that's a good idea.

I'm curious what you think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, unfortunately these 2 are co-dependent: the transaction thread has the iou action's ID as the parent action ID, and vice versa. Also, passing the pre-generated report ID will cause a lot of refactoring of the current methods that use the buildOptimisticChatReport. One possible idea here is to make a separate function that will generate the iouAction, optimisticTransactionThread, and the optimisticCreatedActionForTransactionThread. This way, we'll not be setting the iouAction.childReportID in 4 different places, but in only one function, and will be calling it from those 4 places. It's not perfect either, but will minimize code duplication.

Smth like:

function buildOptimisticIOUReportActionWithTransactionThread(...) {
  const iouAction = ReportUtils.buildOptimisticIOUReportAction(
        CONST.IOU.REPORT_ACTION_TYPE.CREATE,
        amount,
        currency,
        comment,
        [participant],
        optimisticTransaction.transactionID,
        undefined,
        iouReport.reportID,
        false,
        false,
        receiptObject,
        false,
        currentTime,
    );
    const optimisticTransactionThread = ReportUtils.buildTransactionThread(iouAction, iouReport.reportID);
    iouAction.childReportID = optimisticTransactionThread.reportID;
    const optimisticCreatedActionForTransactionThread = ReportUtils.buildOptimisticCreatedReportAction(payeeEmail);


  return { iouAction, optimisticTransactionThread, optimisticCreatedActionForTransactionThread }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought of that but wasn't convinced it would be better. But on second thought, I do think it's better and we can add a comment inside that function above where we set iouAction.childReportID so people know not to remove it.

The alternative would be to put that comment in 4 places, and we'd have that code duplicated like you said, and nothing prevents people from forgetting to set iouAction.childReportID

I'm good to update to this 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✔️

@situchan I've re-tested the 4 different flows that use the 4 different functions that call this new buildOptimisticMoneyRequestEntities function – everything works as expected (except for the known Complete Split BE issue):

  • Send Money
  • Request Money
  • Split right away (the fixed amount split)
  • Split with Complete Split (the scan split)

@paultsimura paultsimura requested a review from cead22 March 10, 2024 11:37
@paultsimura
Copy link
Contributor Author

@cead22 while testing, I've noticed a (relatively unrelated) issue with the SendMoney flow – we don't properly pass the optimistic CREATED actions:

Screen.Recording.2024-03-10.at.19.12.42-compressed.mp4

But to fix it, we need another BE fix. Should we hold for it, or can we make it a separate issue?

@situchan
Copy link
Contributor

@cead22 while testing, I've noticed a (relatively unrelated) issue with the SendMoney flow – we don't properly pass the optimistic CREATED actions:

Screen.Recording.2024-03-10.at.19.12.42-compressed.mp4
But to fix it, we need another BE fix. Should we hold for it, or can we make it a separate issue?

yes, I noticed that as well but that should not really block this PR to be merged

): [OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport, OptimisticCreatedReportAction] {
const iouActionCreationTime = DateUtils.getDBTime();

// The `CREATED` action must be optimistically generated before the IOU action so that it won't appear after the IOU action in the chat.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💚 great comment

@cead22 cead22 merged commit 6e42e55 into Expensify:main Mar 11, 2024
17 checks passed
Copy link

melvin-bot bot commented Mar 11, 2024

@cead22 looks like this was merged without a test passing. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@melvin-bot melvin-bot bot added the Emergency label Mar 11, 2024
@cead22
Copy link
Contributor

cead22 commented Mar 11, 2024

All checks passed and everything was green when I merged. This wasn't an emergency change
image

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/cead22 in version: 1.4.51-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 1.4.51-3 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants